SELECT column1, column2, ... FROM 模式名.表名 [WHERE 条件] [GROUP BY 列名] [ORDER BY 列名 [ASC|DESC]] [HAVING 条件];
-- 创建学生表 CREATE TABLE STUDENTS( STUDENT_ID INTEGER PRIMARY KEY IDENTITY(1,1), NAME VARCHAR(50) NOT NULL, BIRTH_DATE DATE NOT NULL, GENDER CHAR(1) CHECK (GENDER IN ('M','F')) NOT NULL, EMAIL VARCHAR(100) UNIQUE NOT NULL, PHONE_NUMBER VARCHAR(15) ); -- 创建教师表 CREATE TABLE TEACHERS( TEACHER_ID INTEGER PRIMARY KEY IDENTITY(1,1), NAME VARCHAR(50) NOT NULL, EMAIL VARCHAR(100) UNIQUE NOT NULL, PHONE_NUMBER VARCHAR(15), TITLE VARCHAR(30) ); -- 创建课程表 CREATE TABLE COURSES( COURSE_ID INTEGER PRIMARY KEY IDENTITY(1,1), COURSE_NAME VARCHAR(100) NOT NULL, DESCRIPTION TEXT, CREDITS INTEGER NOT NULL ); -- 创建注册表 CREATE TABLE REGISTRATIONS( STUDENT_ID INTEGER, COURSE_ID INTEGER, REGISTRATION_DATE DATE NOT NULL, GRADE CHAR(1) CHECK (GRADE IN ('A','B','C','D','F')), PRIMARY KEY (STUDENT_ID, COURSE_ID), FOREIGN KEY (STUDENT_ID) REFERENCES STUDENTS (STUDENT_ID), FOREIGN KEY (COURSE_ID) REFERENCES COURSES (COURSE_ID) ); -- 创建授课表 CREATE TABLE TEACHING_ASSIGNMENTS( TEACHER_ID INTEGER, COURSE_ID INTEGER, SEMESTER VARCHAR(10) NOT NULL, YEAR INTEGER NOT NULL, PRIMARY KEY (TEACHER_ID, COURSE_ID, SEMESTER, YEAR), FOREIGN KEY (TEACHER_ID) REFERENCES TEACHERS (TEACHER_ID), FOREIGN KEY (COURSE_ID) REFERENCES COURSES (COURSE_ID) ); -- 创建索引以优化查询性能(根据需要来创建) CREATE INDEX idx_students_email ON STUDENTS (EMAIL); CREATE INDEX idx_teachers_email ON TEACHERS (EMAIL); CREATE INDEX idx_courses_name ON COURSES (COURSE_NAME); CREATE INDEX idx_registrations_student ON REGISTRATIONS (STUDENT_ID); CREATE INDEX idx_registrations_course ON REGISTRATIONS (COURSE_ID); CREATE INDEX idx_teaching_assignments_teacher ON TEACHING_ASSIGNMENTS (TEACHER_ID); CREATE INDEX idx_teaching_assignments_course ON TEACHING_ASSIGNMENTS (COURSE_ID);
create or replace procedure mytest_proc( parm_OPType in int:=null, parm_cName in VARCHAR:='', parm_info OUT int:=null -- 输出参数:用户信息 ) as declare inparm_sql VARCHAR2(100); -- 声明局部变量 inparm_value VARCHAR2(100); -- 声明局部变量 --declare --OPType int:=0; --cName varchar(50):=''; --counter int:=0; begin
if parm_OPType=101 begin --select 1 as iResult,'查询到' as cResult; SELECT top 10 * from PRODUCTION."PRODUCT_CATEGORY" order by PRODUCT_CATEGORYID DESC;
--select count(*) into inparm_value from PRODUCTION."PRODUCT_CATEGORY"; --INTO -- parm_info := inparm_value; -- 将查询结果赋值给输出参数 return; end ELSE BEGIN select -1 as iResult,'没有查询到' as cResult; return; --print('22222222'); end;